<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div class="v-code">
        <div class="code_show">
            <span class="code" id="checkCode"></span>
            <a id="link">看不清换一张</a>
        </div>

        <div class="input_code">
            <label for="inpuCode">验证码：</label>
            <input type="text" id="inputCode">
            <span id="text_show"></span>
        </div>
        <input id="Buttonl" type="button" value="确定">
    </div>

    <script>
        // 生成随机验证码方法
        function getCode() {
            var arr = ['a', 'b', 'c', 'd', 'e', 'f','0','1', '2', '3', '4', '5', '6', '7', '8','9'];
            var str = '';
            for(var i=0;i<6;i++){
                var num = Math.round(Math.random()*15);
                str += arr[num];
            }
            return str;
        }
        // 初始化验证码
        document.getElementById('checkCode').innerText = getCode();
        // 点击刷新验证码
        document.getElementById('link').onclick = function(){
            document.getElementById('checkCode').innerText = getCode();
        }

        //点击确定时对比验证码
        document.getElementById('Buttonl').onclick = function(){
            var code1 = document.getElementById('checkCode').innerText;
            var code2 = document.getElementById('inputCode').value;
            if(code1 != code2){
                alert('您输入的验证码不正确');
                document.getElementById('inputCode').value = '';
                return false;
            }
        }
    </script>
</body>
</html>